package io.renren.common.test;

import io.renren.common.utils.BaseFunctionalTesting;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.util.List;

/**
 * Created by Pere
 * Date 2017-05-20
 */
public class TransportData extends BaseFunctionalTesting {

    @Test
    public void goToGoogleSearch () throws Exception{
        try{
            initWebDriver();
            // now use webDriver to visit Google
            webDriver.get("https://tms.starpost.cn/order");


            Thread.sleep(2000);
            // Find the text input element by its name
            webDriver.findElement(By.name("username")).sendKeys("xuxiaogang");
            webDriver.findElement(By.name("password")).sendKeys("xu123456");
            // Enter something to search for
           // element.sendKeys("xuxiaogang");
            // Enter something to search for
            //element1.sendKeys("xu123456");
            webDriver.findElement(By.id("sub-btn")).click();
            // Now submit the form. WebDriver will find the form for us from the element
            //element.submit();
            // Check the title of the page
            System.out.println("Page title is: " + webDriver.getTitle());
            Thread.sleep(2000);
            WebElement e1 = webDriver.findElement(By.xpath("//ul//li[1]"));
            System.out.println(e1.getText());
            Thread.sleep(5000);
            webDriver.findElement(By.xpath("//ul//li[2]")).click();
            Thread.sleep(5000);
            webDriver.findElement(By.xpath("//ul//li[3]")).click();
            Thread.sleep(5000);
            webDriver.findElement(By.xpath("//ul//li[2]")).click();
            Thread.sleep(5000);
            webDriver.findElement(By.xpath("//textarea[1]")).sendKeys("SPUSS1912120081");
            Thread.sleep(10000);
            webDriver.findElement(By.xpath("//button[1]")).click();//点击查询
            Thread.sleep(5000);
            List<WebElement> tds =webDriver.findElements(By.tagName("td"));
            for(WebElement e:tds){
                System.out.println(e.getText());
            }
            // Google's search is rendered dynamically with JavaScript.
            // Wait for the page to load, timeout after 10 seconds
       /* (new WebDriverWait(webDriver,1000)).until(new ExpectedCondition<Boolean>() {

            public Boolean apply (WebDriver d) {


                return d.getTitle().toLowerCase().startsWith("cheese!");
            }
        });*/

            // Should see: "cheese! - Google Search"
            System.out.println("Page title is: " + webDriver.getTitle());
        }finally {
            destroyWebDriver();
        }
        Thread.sleep(112000);
    }
}
